package com.example.bookkeepingelf.business.database.converter;

import androidx.room.TypeConverter;

import java.math.BigDecimal;
import java.math.RoundingMode;

public class BigDecimalConverter {

    @TypeConverter
    public static String fromBigDecimal(BigDecimal value) {
        // 保留两位小数
        return value.setScale(2, RoundingMode.HALF_UP).toPlainString();
    }

    @TypeConverter
    public static BigDecimal toBigDecimal(String value) {
        return value == null ? null : new BigDecimal(value).setScale(2, RoundingMode.HALF_UP);
    }
}